-
Notifications
You must be signed in to change notification settings - Fork 988
Add option to explicitly set app version for telemetry #9388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Summary of ChangesHello @andrewbrook, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the telemetry package by providing a mechanism for developers to explicitly define their application's version. This version information is crucial for distinguishing different deployments of web applications within telemetry data, improving the clarity and utility of collected metrics. The change involves updating the core telemetry API, its underlying service, and associated documentation and tests to support this new configuration option. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces an appVersion option for telemetry, which is a valuable addition for distinguishing application deployments. The changes are well-structured, covering API definitions, documentation, implementation, and tests. My review focuses on improving correctness for edge cases, strengthening encapsulation, and enhancing the robustness of the tests. Overall, this is a solid contribution.
packages/telemetry/src/service.ts
Outdated
| import { LoggerProvider } from '@opentelemetry/sdk-logs'; | ||
|
|
||
| export class TelemetryService implements Telemetry, _FirebaseService { | ||
| _options?: TelemetryOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backing field _options for the options property is currently public. To ensure proper encapsulation and prevent direct modification from outside the class, it should be made private. The public options getter and setter are the intended way to interact with this property.
| _options?: TelemetryOptions; | |
| private _options?: TelemetryOptions; |
| if ((telemetry as TelemetryService).options?.appVersion) { | ||
| appVersion = (telemetry as TelemetryService).options!.appVersion!; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current check for appVersion uses a truthiness check, which will incorrectly handle an empty string ('') as a version. If a user explicitly provides an empty string, it will be treated as falsy, and the appVersion will default to 'unset'. To correctly handle all string values, including empty ones, you should check for null or undefined instead.
| if ((telemetry as TelemetryService).options?.appVersion) { | |
| appVersion = (telemetry as TelemetryService).options!.appVersion!; | |
| } | |
| if ((telemetry as TelemetryService).options?.appVersion != null) { | |
| appVersion = (telemetry as TelemetryService).options.appVersion; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An empty string should map to unset
packages/telemetry/src/api.test.ts
Outdated
| const telemetry = { | ||
| ...fakeTelemetry, | ||
| options: { | ||
| appVersion: '1.0.0' | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test creates a plain object that structurally mimics a TelemetryService instance. This approach is not type-safe and relies on the internal implementation detail of captureError casting the telemetry object. A more robust and type-safe approach would be to instantiate TelemetryService directly, which will make the test less brittle to future refactoring.
| const telemetry = { | |
| ...fakeTelemetry, | |
| options: { | |
| appVersion: '1.0.0' | |
| } | |
| }; | |
| const telemetry = new TelemetryService( | |
| fakeTelemetry.app, | |
| fakeTelemetry.loggerProvider | |
| ); | |
| telemetry.options = { | |
| appVersion: '1.0.0' | |
| }; |
Size Report 1Affected Products
Test Logs |
Size Analysis Report 1Affected Products
Test Logs |
Discussion
"App version" will be used by the telemetry package to distinguish deployments of web applications. This is the most basic implementation, requiring developers to explicitly specify the version information.
Testing
Manual testing, unit testing
API Changes
N/A